package state.fromCsdn;

import state.fromCsdn.impl.NormalState;
import state.fromCsdn.impl.OverdraftState;
import state.fromCsdn.impl.RestrictedState;

/**
 * 状态抽象
 */
public abstract class AccountState {

    protected Account acc;

    /**
     * 存款
     * @param amount
     */
    public abstract void deposit(Double amount);

    /**
     * 取款
     * @param amount
     */
    public abstract void withdraw(Double amount);

    /**
     * 计算手续费
     */
    public abstract void computeInterest();

    /**
     * 切换State
     */
    public void stateCheck() {
        if (acc.getBalance() >= 0) {
            acc.setState(new NormalState(this.acc));
        } else if (acc.getBalance() > -2000) {
            acc.setState(new OverdraftState(this.acc));
        } else {
            acc.setState(new RestrictedState(this.acc));
        }
    }
}
